﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>进入和离开的过渡效果</title>
</head>

<body>
    <style>
        .list-item {
            display: inline-block;
            margin-right: 10px;
        }

        .list-enter-active, .list-leave-active {
            transition: all 1s;
        }

        .list-enter,
        .list-leave-to {
            opacity: 0;
            transform: translateY(30px);
        }
    </style>

    <div id="app" class="demo">
        <button v-on:click="add">添加</button>
        <button v-on:click="remove">移除</button>
        <transition-group name="list" tag="p">
            <span v-for="item in items" v-bind:key="item" class="list-item">
                {{ item }}
            </span>

        </transition-group>
    </div>


    <!--引入vue文件-->
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script>
        const vm = Vue.createApp({
            data() {
                return {
                    items: [10, 20, 30, 40, 50, 60, 70, 80, 90],
                    nextNum: 10
                }
            },
            methods: {
                randomIndex: function () {
                    return Math.floor(Math.random() * this.items.length)
                },
                add: function () {
                    this.items.splice(this.randomIndex(), 0, this.nextNum++)
                },
                remove: function () {
                    this.items.splice(this.randomIndex(), 1)
                }
            }
        }).mount('#app');
    </script>
</body>

</html>